package model

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);not null"`
	Password string `gorm:"type:varchar(32);not null"`
	HeadImg  string `gorm:"type:varchar(500);not null"`
	Nickname string `gorm:"type:varchar(32);not null"`
}

func (u *User) FindUserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile=?", mobile).Find(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(u).Error
}

func (u *User) Register(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UpdatePassword(db *gorm.DB, password string) error {
	return db.Debug().Updates(u).Error
}
